package com.cln.treewalker;

public class TreeNode implements IVisitable, ITreeNode {

	private TreeNode rightChild;
	private TreeNode leftChild;
	protected String treeNodeString;

	public TreeNode() {
		super();
	}

	public TreeNode(String treeNodeString) {
		this.treeNodeString = treeNodeString;
	}

	public boolean equals(Object anotherTreeNode) {
		if (anotherTreeNode instanceof TreeNode) {
			return treeNodeString.equals(((TreeNode) anotherTreeNode)
					.getTreeNodeString());
		} else {
			return false;
		}
	}

	public boolean isLeaf() {
		return getLeftChild() == null && getRightChild() == null;
	}

	public TreeNode getRightChild() {
		return rightChild;
	}

	public void setRightChild(TreeNode rightChild) {
		this.rightChild = rightChild;
	}

	public TreeNode getLeftChild() {
		return leftChild;
	}

	public void setLeftChild(TreeNode leftChild) {
		this.leftChild = leftChild;
	}

	public String getTreeNodeString() {
		return this.treeNodeString;
	}

	public void accept(IVisitor v) {
			v.visit(this);
	}

}